import { Button, Form } from 'antd';
import action from './action';
import BtnEnum from './BtnEnum';
import { connect } from 'dva';
import _ from 'lodash'

export default connect(
  ({ forms }: any) => ({
    BtnConfig: forms?.BtnConfig?.BtnConfig
  })
)(({ dispatch, BtnConfig }: any) => {
  
  //后端提供的 动态 button list  activityBtnList
  const activityBtnList = [
    {
      index: 1,
      btncode: BtnEnum?.submit,
    },
    {
      index: 2,
      btncode: BtnEnum?.save,
    },
  ];


  const actualActivityBtnList = !_.isEmpty(BtnConfig) ?
    activityBtnList.filter((list) => {
      return (
        Object.keys(BtnConfig).includes(list?.btncode)
      );
    }) : activityBtnList
  return (
    <>
      {
        actualActivityBtnList.map((BtnList) => {
          return (
            <Button onClick={
              action({
                dispatch,
                index: BtnList?.index,
                actionConfig: {
                  ...BtnConfig?.[BtnList?.btncode]
                }
              })}>
              {BtnList?.btncode}
            </Button>
          );
        })}
    </>
  );
});
